package net.cityside.summer.web.security;

import net.cityside.summer.domain.User;
import net.cityside.summer.serivce.IUserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

public class UserDetailService implements UserDetailsService {

	@Autowired
	private IUserService userService;

	@Override
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException {
		User user = userService.getUserWithAuthoritiesByUsername(username);
		if (user == null) {
			throw new UsernameNotFoundException(username);
		}
		return new SecuredUser(user);
	}

}
